package com.atguigu.utils;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @className: ThreadPoolUtil
 * @author: LinCong
 * @description:
 * @date: 2023/2/15 19:25
 * @version: 1.0
 */
public class ThreadPoolUtil {

    private static ThreadPoolExecutor threadPoolExecutor;

    private ThreadPoolUtil(){}

    public static ThreadPoolExecutor getThreadPoolExecutor(){
//        懒汉式有线程安全问题
        if (threadPoolExecutor==null){
            synchronized (ThreadPoolUtil.class){
                if (threadPoolExecutor==null){
//                    一个并行的一个初始化，线程池线程数量跟kafak分区数量没有关系，跟压测并发度与实际并发度的比例相关（12000：3000），一般是大于比例数
                    threadPoolExecutor=new ThreadPoolExecutor(5,
                            20,
                            100,
                            TimeUnit.SECONDS,
                            new LinkedBlockingDeque<>());
                }
            }

        }

        return threadPoolExecutor;
    }

}
